import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:oli/widget/BackgroundDecoration.dart';
import 'package:oli/widget/EditProfileButton.dart';
import 'package:oli/widget/InfoCard.dart';
import 'package:oli/widget/UserInfoHeader.dart';

import 'logic.dart';

class MinePage extends StatelessWidget {
  const MinePage({super.key});

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<MineLogic>();
    final state = logic.state;

    return Scaffold(
      body: Stack(
        children: [
          const BackgroundDecoration(),
          SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                const SizedBox(height: 60),
                Obx(() {
                  if (state.userInfo.value == null && !state.isLoggedIn.value) {
                    return const Center(
                      child: CircularProgressIndicator(
                        color: Color(0xFFD4AF37),
                      ),
                    );
                  }
                  return UserInfoHeader(
                    nickname: state.userInfo.value?.nickname,
                    avatarUrl: state.userInfo.value?.avatarUrl,
                    memberLevel: state.userInfo.value?.memberLevel,
                    onLevelTap: () {
                      print("客户点击了 mine 页面的等级");
                    },
                    isLoggedIn: state.isLoggedIn.value,
                  );
                }),
                const SizedBox(height: 30),
                Obx(() {
                  if (state.userInfo.value == null || !state.isLoggedIn.value) {
                    return const SizedBox();
                  }
                  return InfoCard(
                    email: state.userInfo.value!.email,
                    vehicleVins: state.userInfo.value!.vehicleVins,
                  );
                }),
                const SizedBox(height: 40),
                Obx(() {
                  if (state.userInfo.value == null || !state.isLoggedIn.value) {
                    return const SizedBox();
                  }
                  return EditProfileButton(
                    onPressed: () {
                      Get.snackbar('操作', '按钮已点击！');
                    },
                  );
                }),
                const SizedBox(height: 60),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
